angular.module('meRecommendListservices', [])

  .factory('MeRecommendList', function ($resource, $rootScope, ENV) {


    //设置访问接口路径
    var APIUrl = ENV.api;

    //访问获取用户信息的接口
    var recommendListResource = $resource(APIUrl + "meRecommendWine/getMeWineRecommend.do");
    var delMemberNewWineResource = $resource(APIUrl + "meRecommendWine/delMemberNewWine.do");


    var recommendListJson;
    var deleteWineJson;

    var winesForAdd;

    return {

      //获取用户的推荐酒款列表
      getRecommendListInfo : function (memberId){
        recommendListResource.save(
          {member_id : memberId},
          function (data) {
            recommendListJson = data;
            $rootScope.$broadcast('Me.getRecommendListInfo');
          }
        );
      },

      //返回推荐酒款列表
      getRecommendListJson : function(){
        return recommendListJson;
      },

      //删除会员保存的酒款
      deleteWine : function (memberId,deleteWineIdList){
        delMemberNewWineResource.save(
          {
            member_id : memberId,
            idList : deleteWineIdList
          },
          function(data){
            deleteWineJson = data;
            $rootScope.$broadcast('Me.deleteWine');
          }
        );
      },

      getDeleteWineJson : function () {
        return deleteWineJson;
      },

      //设置为历史酒单 添加的酒款
      setSelectWineForAdd : function (list){
        winesForAdd = list;
      },
      getSelectWineForAdd : function (){
        return winesForAdd;
      }


    };

  });
